const p1 = new Promise((resolve, reject) => {
    setTimeout(() => {
        reject(100)
    }, 3000)
})
const p2 = new Promise((resolve, reject) => {
    setTimeout(() => {
        reject(100)
    }, 1000)
})


// 如果其中一个成功了 就会走成功 取出的是第一个成功的值， 都失败了 才会走失败

Promise.any = function (promiseArr) {
    let sum = 0;
    return new Promise((resolve, reject) => {
        const len = promiseArr.length;
        promiseArr.forEach((currentPromise) => {
            Promise.resolve(currentPromise).then(data => {
                resolve(data)
            }, reason => {
                sum++
                if (sum === len) {
                    reject(new Error('All promise were rejected'))
                }
            })
        })
    })
}
Promise.any([p1, p2]).then(data => {
    console.log(data)
}).catch(err => {
    console.log(err)
})

const stringArr = ['2021','2020','2023','2022']
const newArr = stringArr.sort((a,b)=>a-b)
console.log(newArr)